package beans;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import model.AtributoMR;
import service.AtributoMRService;

/**
 * Classe controladora para o módulo relacionado ao dicionário e elementos do MER
 * @author Eduardo, Maylon e Kamilla
 */
@ManagedBean
@ViewScoped
public class AtributoMRBean implements Serializable{
     private List<AtributoMR> AtributosMR;
     private AtributoMR AtributoMR;
     private AtributoMRService control;
     
  
    public AtributoMRBean() {
        control = new AtributoMRService();
        this.atualizarAtributosMR();
        this.criar();
    }

    public AtributoMR getAtributoMR() {
        return AtributoMR;
    }

    public void setAtributoMR(AtributoMR AtributoMR) {
        this.AtributoMR = AtributoMR;
    }

    public List<AtributoMR> getAtributosMR() {
        return AtributosMR;
    }

    public void setAtributosMR(List<AtributoMR> AtributosMR) {
        this.AtributosMR = AtributosMR;
    }

    
   
    public final void criar()  {
        setAtributoMR(new AtributoMR());
    }
    
    public void salvar() {
        
        control.salvar(AtributoMR);
        atualizarAtributosMR();
        this.criar();
    }

    
    public void excluir(){
        control.excluir(AtributoMR);
        atualizarAtributosMR();
    }

    /**
     * Atualiza a lista de tipos de admissão.
     */
    private void atualizarAtributosMR() {
        AtributosMR = control.recarregar();
        if(AtributosMR!=null && !AtributosMR.isEmpty()){
            AtributoMR = AtributosMR.get(0);
        }
    }
   
}
